package testimplicit

/**
  * Created by Germmy on 2018/4/9.
  */

object  GodnessChoose{
  implicit  object orderingGirl extends Ordering[Girl]{
    override def compare(x: Girl, y: Girl): Int = if (x.faceValue>y.faceValue) 1 else -1
  }
}

class Godness[T:Ordering](val g1:T,val g2:T) {//不太理解，在类的后面搞个Godness[T:Ordering]是啥鸡吧意思 ？

  def choose()(implicit order:Ordering[T]) = if (order.gt(g1,g2)) g1 else g2//这个地方不太好理解。
  //1.为啥implicit后面不是implicit order:T
  //2.还是要好好看下JAVA里面的泛型，我日，迷惑了多少年

}


class Girl(val name:String,val faceValue:Int){
  override def toString:String=s"name:$name,faceValue:$faceValue"
}


object Godness{
  def main(args: Array[String]) {

    val g1=new Girl("二彪",90)
    val g2=new Girl("二吊",80)
    import GodnessChoose.orderingGirl
    val res=new Godness[Girl](g1,g2).choose()
    println(res)
  }
}
